/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.scene.controller;

import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.domain.DataBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.hiddendanger.uitls.BusinessCode;
import com.koron.scene.domain.Moments;
import com.koron.scene.service.api.MomentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.swan.bean.MessageBean;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "moments", description = "朋友圈相关接口类")
@RestController
@RequestMapping("/moments")
public class MomentsController {

    @Autowired
    private MomentsService service;

    @ApiOperation("朋友圈动态列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "corpCode" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数" , dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/list.htm", method = RequestMethod.GET)
    public MessageBean<DataBean<Moments>> list(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user,
                                               @RequestParam String corpCode,
                                               @RequestParam Integer page,
                                               @RequestParam Integer pageSize) {
        if (null == user) {
            return MessageBean.create(BusinessCode.NOT_LONGIN.getCode(), BusinessCode.NOT_LONGIN.getDescription(), null);
        }
        MessageBean<DataBean<Moments>> msg = ADOConnection.runTask(factory -> service.list(factory, user,corpCode, page, pageSize), MessageBean.class);
        if (null != msg.getData()) {
            msg.getData().setPageNo(page);
        }
        return msg;
    }


    @ApiOperation("查询朋友圈动态详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "朋友圈动态id", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/details.htm", method = RequestMethod.GET)
    public MessageBean<Moments> details(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam final String id) {
        if (null == user) {
            return MessageBean.create(BusinessCode.NOT_LONGIN.getCode(), BusinessCode.NOT_LONGIN.getDescription(), Moments.class);
        }
        return ADOConnection.runTask(factory -> service.queryOne(factory, user, id), MessageBean.class);
    }


    @ApiOperation("保存朋友圈评论接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "momentId", value = "朋友圈动态id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "commentId", value = "评论id" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "content", value = "评论内容", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/saveComment.htm", method = RequestMethod.POST)
    public MessageBean<?> saveComment(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam final String momentId, @RequestParam(required = false) String commentId, @RequestParam final String content) {
        if (null == user) {
            return MessageBean.create(BusinessCode.NOT_LONGIN.getCode(), BusinessCode.NOT_LONGIN.getDescription(), Moments.class);
        }
        return ADOConnection.runTask(factory -> service.saveComment(factory, user, momentId,commentId, content), MessageBean.class);
    }


    @ApiOperation("保存朋友圈点赞接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "momentId", value = "朋友圈动态id", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/saveLike.htm", method = RequestMethod.POST)
    public MessageBean<?> saveLike(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam final String momentId) {
        if (null == user) {
            return MessageBean.create(BusinessCode.NOT_LONGIN.getCode(), BusinessCode.NOT_LONGIN.getDescription(), Moments.class);
        }
        return ADOConnection.runTask(factory -> service.saveLike(factory, user, momentId), MessageBean.class);
    }


    @ApiOperation("查询朋友圈评论详情接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "评论id", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/commentDetails.htm", method = RequestMethod.GET)
    public MessageBean<?> commentDetails(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam final String id) {
        if (null == user) {
            return MessageBean.create(BusinessCode.NOT_LONGIN.getCode(), BusinessCode.NOT_LONGIN.getDescription(), Moments.class);
        }
        return ADOConnection.runTask(factory -> service.commentDetails(factory, id), MessageBean.class);
    }

}
